<template>
    <div class="container">
        <van-nav-bar title="购物车" left-text="返回" left-arrow @click-left="onClickLeft" />
        <main>
      <van-empty description="购物车" v-if="cartList.length == 0" />
      <div class="cart-list" v-else>
        <van-swipe-cell  v-for="(item,index) in cartList">
          <van-row>
            <van-col span="2">
                <van-checkbox style="margin-top: 40px;margin-left: 12px" v-model="item.flag"></van-checkbox>
            </van-col>
            <van-col span="22">
              <van-card :price="item.originprice" :title="item.proname" class="goods-card"
            :thumb="item.img1">
            <template #num>
              <van-stepper v-model="item.num" theme="round" button-size="22" disable-input />
            </template>
          </van-card>
            </van-col>
          </van-row>
          <template #right>
            <van-button square text="删除" type="danger" class="delete-button" @click="deleteMe(item.cartid)"/>
          </template>
          
        </van-swipe-cell>
       
      </div>

    </main>
    <Youhuiquan></Youhuiquan>
        <van-submit-bar :price="sum" button-text="提交订单">
          <van-checkbox v-model="checked">全选</van-checkbox>
        </van-submit-bar>
</div>
</template>
<script>
import { getCartlist, removeChart } from '@/api/cart';
import Youhuiquan from '../cart/componments/Youhuiquan.vue';
    export default {
        props:[''],
        data(){
            return{
                value:1,
                cartList:[],
                checked:true,
                sum:0
            }
        },
        components:{
            Youhuiquan
        },
        created(){
            getCartlist({userid:localStorage.getItem('userid')}).then(res=>{
                console.log(res);
                this.cartList=res.data.data || []
            })
        },
        computed:{

        },
        methods:{
            onClickLeft(){
                history.back()
            },
            onClickLin(){

            },
            onSubmit(){

            },
            deleteMe(index){
                removeChart({cartid:index}).then(res=>{
                    console.log(res)
                    if (res.data.code=="200") {
                        showToast('删除成功')
                        getCartlist({userid:localStorage.getItem('userid')}).then(res=>{
                        this.cartList=res.data.data
                    })
                    }
                }
                )
            }
        }
    }
</script>

<style lang="less" scoped>
.goods-card {
    margin: 0;
    background-color: white;
  }
  .delete-button {
    height: 100%;
  }
</style>